<template>
  <div>
    <!-- <h2>商品展示</h2> -->
    <!-- 下拉菜单 -->
    <van-dropdown-menu>
      <van-dropdown-item
        disabled
        title="综合"
      />
      <van-dropdown-item
        title="价格"
        v-model="priceVal"
        :options="option2"
        @change='priceChange'
      />
      <van-dropdown-item
        title="分类"
        v-model="categoryVal"
        :options="filterCategory"
        @change='categoryChange'
      />
    </van-dropdown-menu>
    <!-- 要么是空 要么是有数据   -->
    <van-empty
      v-if="goodsList.length == 0"
      image="search"
      description="没有您要搜索的产品"
    />
    <Products
      v-else
      :goodsList="goodsList"
    ></Products>
  </div>
</template>

<script>
import Products from "@/components/Products.vue";

export default {
  data() {
    return {
      priceVal: "",
      categoryVal: 1005000,
      option2: [
        { text: "价格由高到低", value: "desc" },
        { text: "价格由低到高", value: "asc" },
      ],
    };
  },
  // 数据挂载完 mounted
  beforeUpdate() {
    // 遍历filterCategory 看看哪一项的 checked为 true
    // 遍历的时候 就把 this.categoryVal 的值改为 他的 value值 这样这一项就被勾上了
    // console.log(this.filterCategory);
    this.filterCategory.map((item) => {
      if (item.checked) {
        // console.log("if-item", item);
        this.categoryVal = item.value;
        return;
      }
    });
  },
  props: ["filterCategory", "goodsList"],
  methods: {
    categoryChange(value) {
      // console.log(value);
      this.$emit("categoryChange", value);
    },
    priceChange(value) {
      // console.log("value", value);
      this.$emit("priceChange", value);
    },
  },
  components: {
    Products,
  },
};
</script>

<style>
</style>